package com.atguigu.jxc.controller;


import com.atguigu.jxc.domain.ErrorCode;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.PurchaseList;
import com.atguigu.jxc.entity.ReturnList;
import com.atguigu.jxc.service.PurchaseListService;
import com.atguigu.jxc.service.ReturnListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * 退货出库
 */
@RestController
@RequestMapping("/returnListGoods")
public class ReturnListGoodsController {

    @Autowired
    private ReturnListGoodsService returnListGoodsService;

    //http://localhost:8080/returnListGoods/save?returnNumber=TH1605768591211（退货单号前端生成）
    //退货单保存
    @PostMapping("/save")
    public ServiceVO saveReturnList(ReturnList returnList, String returnListGoodsStr, HttpSession session){
        try {
            returnListGoodsService.saveReturnList(returnList,returnListGoodsStr,session);
            return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new ServiceVO(ErrorCode.PARA_TYPE_ERROR_CODE, ErrorCode.PARA_TYPE_ERROR_MESS);
        }
    }

    //http://localhost:8080/returnListGoods/list
    //退货单列表展示（可条件查询：单据号模糊、供应商、是否付款和日期区间）
    @PostMapping("/list")
    public Map<String,Object> list(String returnNumber,Integer supplierId, Integer state,String sTime,String eTime){
       return returnListGoodsService.list(returnNumber,supplierId,state,sTime,eTime);
    }

    //http://localhost:8080/returnListGoods/goodsList
    //退货单商品信息 Integer returnListId
    @PostMapping("/goodsList")
    public Map<String,Object> goodsList(Integer returnListId){
        return returnListGoodsService.goodsList(returnListId);
    }

    //http://localhost:8080/returnListGoods/delete
    //删除退货单 Integer returnListId
    @PostMapping("/delete")
    public ServiceVO delete(Integer returnListId){
        try {
            returnListGoodsService.delete(returnListId);
            return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new ServiceVO(ErrorCode.PARA_TYPE_ERROR_CODE, ErrorCode.PARA_TYPE_ERROR_MESS);
        }
    }


    //http://localhost:8080/returnListGoods/updateState
    //修改供应商退货单退款状态 returnListId
    @PostMapping("/updateState")
    public ServiceVO updateState(Integer returnListId){
        ServiceVO  serviceVO=returnListGoodsService.updateState(returnListId);
        return serviceVO;
    }

    //http://localhost:8080/returnListGoods/count
    //退货统计（可根据 商品类别、商品编码或名称 条件查询）
    @PostMapping("/count")
    public String count(String sTime, String eTime ,Integer goodsTypeId, String codeOrName){
        return returnListGoodsService.count(sTime,eTime,goodsTypeId,codeOrName);
    }
}
